package Common;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.util.concurrent.TimeUnit;

/**
 * Created by Esferat on 27.08.2014.
 */

public class TestManager {

    public static final String BASE_URL_PROPERTY = "baseUrl";
    public static final String MAIN_LOGIN_PROPERTY = "mainLogin";
    public static final String MAIN_PASSWORD_PROPERTY = "mainPassword";

    public static final String defaultLogin = "LuisArmstrong";
    public static final String defaultPassword = "SpaceMan";
    public static final String defaultBaseUrl = "http://penton-print2digital-qa.dev.thumbtack.net:3000/";

    private String mainLogin;
    private String mainPassword;
    private String baseUrl;

    private static TestManager instance = new TestManager();


    private WebDriver driver;
    private HelperBase helperBase;
    private Application application;


    private TestManager() {
        // init test params
        baseUrl = System.getProperty(BASE_URL_PROPERTY, defaultBaseUrl);
        mainLogin = System.getProperty(MAIN_LOGIN_PROPERTY, defaultLogin);
        mainPassword = System.getProperty(MAIN_PASSWORD_PROPERTY, defaultPassword);

        System.out.println("Running tests on url: " + baseUrl + " for user " + mainLogin);

        // init web driver
        DesiredCapabilities caps = DesiredCapabilities.firefox();

        //caps.setCapability("nativeEvents", true);
        driver = new FirefoxDriver(caps);
        driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
        driver.manage().window().maximize();
        driver.manage().deleteAllCookies();

        // init helpers
        helperBase = new HelperBase(this);

        application = new Application(this);
    }

    public static TestManager getInstance() {
        return instance;
    }

    public void stop() {
        driver.quit();
    }

    public WebDriver getDriver() {
        return driver;
    }

    public HelperBase getHelperBase() {
        return helperBase;
    }

    public Application getApplication(){return application ;}

    public String getBaseUrl() {
        return baseUrl;
    }

    public String getMainPassword() {
        return mainPassword;
    }

    public String getMainLogin() {
        return mainLogin;
    }
}
